//
//  SYJMainViewController.swift
//  weibo
//
//  Created by 孙英建 on 16/4/16.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class SYJMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()

        // 添加tabbar加号
        let tabbar = SYJTabbar()
        
        // 加号按钮点击闭包
        tabbar.postbuttonclick = {[weak self] in
            let composeVc = SYJComposeViewController()
            
            self!.presentViewController(UINavigationController(rootViewController: composeVc), animated: true, completion: nil)
        }
        
        setValue(tabbar, forKey: "tabBar")
        
        // 添加子控制器
        addChildViewController(SYJHomeViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(SYJDiscoverViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(SYJMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(SYJProfileViewController(), imageName: "tabbar_profile", title: "我的")
        
        
    }

    
    // 添加字控制器的方法
    func addChildViewController(childController: UIViewController, imageName: String, title: String) {
        
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        childController.title = title
        
        addChildViewController(UINavigationController(rootViewController: childController))
    }
  
    

}
